<%@ page contentType="text/html; charset=GBK" import="java.util.*"  %>
<%@ page import="java.io.ByteArrayOutputStream"%>
<%@ page import="com.jiuqi.ezReport.report.Report"%>
<%@ page import="com.jiuqi.ezReport.output.*"%>
<%@ page import="com.jiuqi.common.*" %>
<%@ page import="com.jiuqi.grid.GridData" %>
<%@ include file="/common/inc.jsp" %>
<%
Report report = null;
GridData gridData = null;
if(request.getSession().getAttribute(Constants.REPORT_KEY)!=null)
	{
  		ArrayList reportList =(ArrayList)request.getSession().getAttribute(Constants.REPORT_KEY);
  		report = (Report)reportList.get(0);
  		gridData = (GridData)reportList.get(1);
  		//gridData = (GridData)reportList.get(1);
 	}
	else{
   		//out.print("<script>if(window.parent!=null) window.parent.location.href='"+mainWeb+"/login.jsp'; else window.location.href='"+mainWeb+"/login.jsp'</script>");
              out.println("AAAAAAAAAAAAAAAAAA");
              return;
	}
String autoAdjust = request.getParameter("autoAdjust");
String addTitle = request.getParameter("addTitle");
ExcelExportor excelExportor = new ExcelExportor(report,gridData);
if (addTitle!=null&&addTitle.equalsIgnoreCase("true")){
	excelExportor.setAddTitle(true);
}	
if (autoAdjust!=null&&autoAdjust.equalsIgnoreCase("true")){
	excelExportor.setAutoAdjust(true);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String fileName = "";
if(fileName == null || fileName.equalsIgnoreCase(""))
    fileName = "Report";
else
	fileName = new String(report.getTitle().getBytes("GBK"), "iso8859-1");
  
try{
	excelExportor.export(byteArrayOutputStream);
}catch(Exception ex){
 	ex.printStackTrace();
}
out.clearBuffer();
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-Disposition","attachment; filename=" + fileName + ".xls");
ServletOutputStream servletOut = response.getOutputStream();
byteArrayOutputStream.writeTo(servletOut);
servletOut.close();
%>